//
//  MapData.m
//  DefenseSummoner
//
//  Created by vupham on 5/28/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MapData.h"

@implementation MapData

@synthesize mapBackground,towersPos,ways,wayWidth,waves, startingMoney,numberOfWaypoints;

-(id)initMapData {
    self = [super init];
    mapBackground = [[NSString alloc]init];
    ways = [[NSMutableArray alloc]init];
    waves=[[NSMutableArray alloc]init];
    return self;
}

-(NSMutableArray*)getPointArrayFromTileMapGroup:(CCTMXObjectGroup*)_group{
    NSMutableDictionary *point;
    NSMutableArray *pointArray=[[NSMutableArray alloc ]init];
    for (point in [_group objects]) {
        int x = [[point valueForKey:@"x"] floatValue];
        int y = [[point valueForKey:@"y"] floatValue];
        NSLog(@"Point %d %d",x,y);
        [pointArray addObject:[NSValue valueWithCGPoint:ccp(x,y)]];
    }
    return pointArray;
}

-(void)getWaypointsFromTileMap{
    CCTMXTiledMap *tileMap=[[CCTMXTiledMap alloc]initWithTMXFile:mapBackground];
    for (int i=0;i<numberOfWaypoints;i++){
        CCTMXObjectGroup *waypoint=[tileMap objectGroupNamed:[NSString stringWithFormat:@"Waypoint_%d",i]];
        [ways addObject:[self getPointArrayFromTileMapGroup:waypoint]];
    }
    [tileMap release];
}

-(void)getTowersPositionsFromTileMap{
    CCTMXTiledMap *tileMap=[[CCTMXTiledMap alloc]initWithTMXFile:mapBackground];
    CCTMXObjectGroup *towerPosition=[tileMap objectGroupNamed:@"TowerPosition"];
    towersPos=[self getPointArrayFromTileMapGroup:towerPosition];
    [tileMap release];
}

@end
